﻿using System;
using System.Collections.Generic;

namespace TableTypes
{
    public class BookTableEntry
    {
        public ClassName ClassName = null;
        public ClassTime ClassTime = null;
        public bool Available = false;
        public int ClassId = 0;

    }

    public class BookTable: List<BookTableEntry>
    {
        public static BookTable Fetch(WebLayer.LoginToken loginToken)
        {
            WebParser.WebPageCache pageCache = new WebParser.WebPageCache();
            pageCache.LoginToken = loginToken;

            return Fetch(pageCache);
        }
        public static BookTable Fetch(WebParser.WebPageCache pageCache)
        {
            WebParser.BookWebPage webPage = pageCache.GetPage<WebParser.BookWebPage>();            

            BookTable bookTable = new BookTable();
            foreach (WebParser.BookClassesTableEntry webEntry in webPage.TableContent)
            {
                BookTableEntry memEntry = new BookTableEntry();
                memEntry.ClassName = ClassName.ParseClassName(webEntry.Class);
                memEntry.ClassTime = ClassTime.ParseBookEntry(webEntry.Date);

                string str = webEntry.Availability;
                if (str.ToLower().Equals("yes"))
                {
                    memEntry.Available = true;
                }
                else
                {
                    memEntry.Available = false;
                }

                memEntry.ClassId = Int32.Parse(webEntry.Book);
                bookTable.Add(memEntry);
            }

            return bookTable;
        }
    }
}
